package com.bsg.upm.service;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONArray;
import com.bsg.upm.dto.ScaleDto;
import com.bsg.upm.entity.DefinitionSubServUnitScaleEntity;
import com.bsg.upm.exception.APIException;
import com.bsg.upm.http.RespJson;
import com.bsg.upm.http.RespJsonFactory;

/**
 * 规模管理业务处理类
 * 
 * @author HCK
 *
 */
@Service
public class ScaleService extends BaseService {

	/**
	 * 获取规模列表
	 * 
	 * @param paramMap
	 *            请求参数
	 * @return 操作结果
	 * @throws APIException
	 *             API异常处理类
	 */
	public RespJson list(Map<String, Object> paramMap) throws APIException {
		try {
			JSONArray retJsonArray = new JSONArray();
			List<DefinitionSubServUnitScaleEntity> scales = definitionSubServUnitScaleDao.list(paramMap);
			for (DefinitionSubServUnitScaleEntity scale : scales) {
				ScaleDto scaleDto = buildShowDto(scale, false);
				retJsonArray.add(scaleDto);
			}
			return RespJsonFactory.buildOK(retJsonArray);
		} catch (Exception e) {
			logger.error("规模查询异常", e);
			throw new APIException("架构查询异常:" + e.getMessage());
		}
	}

	private ScaleDto buildShowDto(DefinitionSubServUnitScaleEntity scale, boolean showDetail) {
		ScaleDto scaleDto = new ScaleDto();
		scaleDto.setId(scale.getId());
		scaleDto.setName(scale.getName());
		scaleDto.setSequence(scale.getSequence());
		scaleDto.setCpuNum(scale.getCpuNum());
		scaleDto.setMemSize(scale.getMemSize());
		scaleDto.setIoWeight(scale.getIoWeight());
		scaleDto.setDefaults(scale.getDefaults());
		return scaleDto;
	}
}
